<?php


namespace app\admin\controller;



use think\Controller;
use think\Db;
use think\Request;
use think\Session;

class Index extends Controller
{
    public function index()
    {

        if (Session::get('pid')){
            return view('main/index');
        }else{
            return  view('index/login');
        }
    }


    public function logindo(Request $request)
    {
        $p=$request->post();
//        dump($p);

        $uid=Db::table('hb_user')
            ->field('id')
            ->where('username',$p['name'])
            ->where('pass',$p['pass'])
            ->find();
//        dump($uid);
        if (!$uid){
            return $this->error('登录错误,请重试!!', 'admin/index/index');
        }else{
            //      $a=  Db::table('user_role')
//            ->where('user_role.u_id','=',$uid)
//            ->select();
//        dump($a);

            $result= Db::field(['p.id','p.permission','p.controller','p.method'])
                ->table(['user_role'=>'ur','role_permission'=>'rp','hb_permission'=>'p'])
                ->where('ur.r_id=rp.r_id and rp.p_id=p.id')
                ->where('ur.u_id',$uid['id'])
                ->select();
//            dump($result);

            foreach ($result as $v)
            {
                $arr[]=$v['id'];
            }
//            dump($arr);

//        设置session
            Session::set('pid',$arr);
//        $a=Session::get('pid');
//        dump($a);
                return view('main/index');
        }











    }


    public function  logout()
    {
        Session::clear();
        return  view('index/login');

    }


}